package ink.ykb.actDemo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import ink.ykb.actDemo.dao.UserInfoDao;
import ink.ykb.actDemo.entity.UserInfo;
import ink.ykb.actDemo.util.Constant;
import ink.ykb.actDemo.util.HttpRequestLocal;
import ink.ykb.actDemo.util.PlatformRuntimeException;

@Service
@Transactional
public class UserService {
	
	@Autowired
	private UserInfoDao userInfoDao;
	@Autowired
	private HttpRequestLocal httpRequestLocal;

	public void login(UserInfo userInfo) {
		if(userInfo == null || userInfo.getName() == null ) {throw new PlatformRuntimeException("姓名不能为空");}
		UserInfo user = userInfoDao.createLambdaQuery().andEq(UserInfo::getName, userInfo.getName()).single();
		if(user == null) {throw new PlatformRuntimeException("查询不到此用户");}
		
		httpRequestLocal.setSessionValue(Constant.SESSION_USER_ID, user.getId());
		
	}
}
